package com.jsjosem.aftersales.request;

import androidx.core.util.Consumer;

import com.jsjosem.aftersales.api.FileApi;
import com.jsjosem.aftersales.data.response.BaseResponse;
import com.jsjosem.aftersales.data.response.FileResponse;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;

public class FileRequest extends AsyncRequest<BaseResponse<FileResponse>> {

    public void uploadFile(File file, Consumer<BaseResponse<FileResponse>> success, Consumer<? super Object> failed) {
        FileApi request = retrofit.create(FileApi.class);
        RequestBody imageBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
        MultipartBody.Part imageBodyPart = MultipartBody.Part.createFormData("attachment", file.getName(), imageBody);
        Call<BaseResponse<FileResponse>> uploadFile = request.uploadFile(imageBodyPart);
        sendRequest(uploadFile, success, failed);
    }

}
